/*
// Definition for Employee.
class Employee {
public:
    int id;
    int importance;
    vector<int> subordinates;
};
*/

class Solution {
public:
    int getImportance(vector<Employee*> employees, int id) {
        unordered_map<int, Employee*> hash;
        for (int i = 0; i < employees.size(); i++)
            hash[employees[i]->id] = employees[i];
        int ret = 0;
        queue<Employee*> q;
        q.push(hash[id]);
        while (!q.empty())
        {
            Employee* employee = q.front();
            q.pop();
            ret += employee->importance;
            vector<int>& subordinates = employee->subordinates;
            for (auto id : subordinates)
                q.push(hash[id]);
        }
        return ret;
    }
};